package com.david.dubbo.xml;

import com.david.dubbo.xml.domain.User;
import com.david.dubbo.xml.service.DavidService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @author David
 * @version V1.0
 * @Package com.david.dubbo.xml
 * @date 2021/4/11 10:02
 */
public class DavidConsumerApplication {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:dubbo-consumer.xml");
        context.start();
        DavidService service = context.getBean(DavidService.class);
        //此时返回的User 是null
        User user = service.queryUserById(5);
        System.out.println("user = " + user);

        //模拟做其他业务逻辑，耗时1秒
        Thread.sleep(10l);
        //此次获取异步调用的结果
        Future<User> future = RpcContext.getContext().getFuture();
        User o = future.get();
        System.out.println("异步调用结果：" + o);

    }
}
